package viewdraw.zjitc.net.androidhomeworkviewdraw;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author 朱志文
 * @data 2019/10/15 0015
 */
public class MyView extends View {
    private Object newW;
    private Object newH;

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     *
     * @param canvas 画布
     */
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //绘制画布的颜色
        canvas.drawColor(Color.WHITE);
        //画笔 样式 颜色 粗细
        Paint paint=new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(2);

        //点
        canvas.drawPoint(750,750,paint);

        //线
        canvas.drawLine(550,750,750,750,paint);

        //圆心
        canvas.drawCircle(750,750,200,paint);

        //矩形
        Rect rect=new Rect(550,550,950,950);
        canvas.drawRect(rect,paint);

        //圆角矩形
        RectF rectF=new RectF(500,550,1000,950);
        canvas.drawRoundRect(rectF,70,70,paint);

        //椭圆
        RectF oval=new RectF(500,550,1000,950);
        canvas.drawOval(oval,paint);

        //bitmap
        Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.dm1);
        float viewWidth= getWidth();
        float bitMapHeight= bitmap.getHeight();
        float bitMapWidth=bitmap.getWidth();
        float viewHeght=(viewWidth/bitMapWidth)*bitMapHeight;
        canvas.drawBitmap(bitmap,null,new RectF(0,0,viewWidth,viewHeght),paint);


        
    }



}
